<?php

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * @see Zend_Gdata_Entry
 */
require_once 'Zend/Gdata/Entry.php';

/**
 * @see Zend_Gdata_Finance_Extension_PortfolioData
 */
require_once 'Zend/Gdata/Finance/Extension/PortfolioData.php';

/**
 * @see Zend_Gdata_App_Extension_Category
 */
require_once 'Zend/Gdata/App/Extension/Category.php';

/**
 * @see Zend_Gdata_Finance_Extension_Symbol
 */
require_once 'Zend/Gdata/Finance/Extension/Symbol.php';

/**
 * Data model class for a Portfolio Entry.
 *
 * To transfer user entries to and from the servers, including
 * creating new entries, refer to the service class,
 * Zend_Gdata_Finance.
 *
 * This class represents <atom:entry> in the Google Data protocol.
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Gdata_Finance_PortfolioEntry extends Zend_Gdata_Entry
{

	protected $_entryClassName = 'Zend_Gdata_Finance_PortfolioEntry';
	/**
	 * The symbol object
	 *
	 * @var Zend_Gdata_Finance_Extension_Symbol
	 */
	protected $_symbol = null;
	/**
	 * The detailed porfolio data
	 *
	 * @var Zend_Gdata_Finance_Extension_PortfolioData
	 */
	protected $_portfolioData = null;

	/**
	 * Create a new instance.
	 *
	 * @param string $title Name of portfolio
	 * @param string $currencyCode Default ISO4217 currency code for the portfolio.
	 */
	public function __construct($element = null)
	{
		foreach (Zend_Gdata_Finance::$namespaces as $nsPrefix => $nsUri) {
			$this->registerNamespace($nsPrefix, $nsUri);
		}
		parent::__construct($element);
		$category = new Zend_Gdata_App_Extension_Category(
            'http://schemas.google.com/finance/2007#portfolio',
            'http://schemas.google.com/g/2005#kind');
		$this->setCategory(array($category));

	}

	/**
	 * Retrieves a DOMElement which corresponds to this element and all
	 * child properties.  This is used to build an entry back into a DOM
	 * and eventually XML text for application storage/persistence.
	 *
	 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
	 * @return DOMElement The DOMElement representing this element and all
	 *          child properties.
	 */
	public function getDOM($doc = null)
	{
		$element = parent::getDOM($doc);
		if ($this->_portfolioData !== null) {
			$element->appendChild($this->_portfolioData->getDOM($element->ownerDocument));
		}
		return $element;
	}

	/**
	 * Creates individual Entry objects of the appropriate type and
	 * stores them as members of this entry based upon DOM data.
	 *
	 * @param DOMNode $child The DOMNode to process
	 */
	protected function takeChildFromDOM($child)
	{
		$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;

		switch ($absoluteNodeName) {
			case $this->lookupNamespace('gf') . ':' . 'portfolioData';
			$gf = new Zend_Gdata_Finance_Extension_PortfolioData();
			$gf->transferFromDOM($child);
			$this->_portfolioData = $gf;
			break;
			case $this->lookupNamespace('gf') . ':' . 'symbol';
			$gf = new Zend_Gdata_Finance_Extension_Symbol();
			$gf->transferFromDOM($child);
			$this->_portfolioData = $gf;
			break;
			default:
				parent::takeChildFromDOM($child);
				break;
		}
	}

	/**
	 * Get the value for this elements PortfolioData  attribute.
	 *
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The requested attribute.
	 */
	public function getPortfolioData()
	{
		return $this->_portfolioData;
	}

	/**
	 * Set the value for this elements Portfolio  attribute.
	 *
	 * @param Zend_Gdata_Finance_Extension_PortfolioData $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_PortfolioEntry The element being modified.
	 */
	public function setPortfolioData($value)
	{
		$this->_portfolioData = $value;
		return $this;
	}

	/**
	 * Get the value for this elements Symbol  attribute.
	 *
	 * @return Zend_Gdata_Finance_Extension_Symbol The requested attribute.
	 */
	public function getSymbol()
	{
		return $this->_symbol;
	}

	/**
	 * Set the value for this elements Portfolio  attribute.
	 *
	 * @param Zend_Gdata_Finance_Extension_Symbol $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_PortfolioEntry The element being modified.
	 */
	public function setSymbol($value)
	{
		$this->_symbol = $value;
		return $this;
	}
}
